package com.petmall.service;

import com.petmall.entity.Admin;
import com.petmall.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by pig2guang on 2017/5/3.
 */
@Service
public class AdminService {

    @Autowired
    private AdminMapper adminmapper;

    //管理员登陆
    public Admin loginCheck(Admin admin){
        return adminmapper.selectAdmin(admin.getAdmin_id(), admin.getPassword());
    }

    //获取管理员信息
    public Admin getAdmin(Object admin_id){
        return adminmapper.selectAdminById(admin_id.toString());
    }

    //管理员登陆时间
    public String setLoginTime(String admin_id){
        String login_time = getCurrentTime();
        adminmapper.updateTime(login_time, admin_id);
        return login_time;
    }

    //获取信息最新时间
    private String getCurrentTime(){
        Date date = new Date();
        DateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        String time = format.format(date);
        return time ;
    }

}
